/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package trefliq.EJB.sessionbeans;

import java.sql.Date;
import javax.annotation.security.PermitAll;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import trefliq.EJB.entities.*;

/**
 *
 * @author adam
 */
@Stateless
@LocalBean
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
@PermitAll
public class MovieCreditBean {
    @PersistenceContext(unitName="trefliqPU")
    private EntityManager _em;

    //TODOSEC: @RolesAllowed({SecurityRole.ADMIN, SecurityRole.EMPLOYEE})
    public boolean CreateMovieCredit(Movie movie, ShowBizPeople showbizpeople, Credit credit) {
        MovieCredit instance = new MovieCredit(movie.getId(), showbizpeople.getId(), credit.getId());
         instance.setCredit(credit);
         instance.setMovies(movie);
         instance.setShowBizPeople(showbizpeople);
        try {
            _em.persist(instance);
            _em.close();
        }
        catch (Exception e) {
            return false;          
        }
        return true;
    }
    
    //TODOSEC: @RolesAllowed({SecurityRole.ADMIN, SecurityRole.EMPLOYEE})
    public boolean DeleteMovieCredit(Movie movie, ShowBizPeople showbizpeople, Credit credit) {
        MovieCredit instance = new MovieCredit(movie.getId(), showbizpeople.getId(), credit.getId());
         instance.setCredit(credit);
         instance.setMovies(movie);
         instance.setShowBizPeople(showbizpeople);
         
        try {
            _em.remove(instance);
            _em.close();
        }
        catch (Exception e) {
            return false;          
        }
        return true;
    }


}
